package com.kefu.chat.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.chat.model.ChatChannel;
import com.kefu.chat.model.ChatChannelExtModel;
import com.kefu.chat.model.ChatChannelSideBar;
import com.kefu.chat.service.ChatChannelService;
import com.kefu.chat.vo.*;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import com.kefu.common.vo.DetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags="渠道配置")
@RestController
@RequestMapping("chat/channel")
public class ChatChannelController extends AbstractBaseController{
    @Resource
    private ChatChannelService chatChannelService;

    @PostMapping("/add")
    @ApiOperation(value="新增渠道配置", notes="新增渠道配置")
    public Result<String> add(@Validated @RequestBody ChatChannelInsertVo chatChannelVo) {
    	logger.info("新增渠道配置:{}",chatChannelVo);
    	
    	ChatChannel info = chatChannelVo.convert();
        chatChannelService.save(info);
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/delete")
    @ApiOperation(value="删除渠道配置", notes="删除渠道配置")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
    	logger.info("删除渠道配置:{}",delete);
    	
        chatChannelService.deleteById(delete.getId());
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @ApiOperation(value="修改渠道配置", notes="修改渠道配置")
    public Result<String> update(@Validated @RequestBody ChatChannelUpdateVo chatChannelVo) {
    	logger.info("修改渠道配置:{}",chatChannelVo);
    	
    	ChatChannel info = chatChannelVo.convert();
        chatChannelService.updateChannel(info);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    @ApiOperation(value="渠道配置详情", notes="渠道配置详情")
    public Result<ChatChannelVo> detail(@Validated @RequestBody DetailVo detail) {
        return ResultGenerator.genSuccessResult(chatChannelService.detailById(detail.getId()));
    }

    @PostMapping("/list")
    @ApiOperation(value="查询渠道配置", notes="查询渠道配置")
    public Result<Page<ChatChannel>> list(@Validated @RequestBody ChatChannelSearchVo search) {
        Page<ChatChannel> list = chatChannelService.listChannel(search);
        return ResultGenerator.genSuccessResult(list);
    }

    @PostMapping("/addSideBar")
    @ApiOperation(value="添加侧边栏菜单", notes="添加侧边栏菜单")
    public Result<String> addSideBar(@Validated @RequestBody ChatChannelSideBarInsertVo chatChannelSideBarVo) {
        logger.info("添加侧边栏菜单:{}",chatChannelSideBarVo);

        ChatChannelSideBar info = chatChannelService.addSidebarMenuInfo(chatChannelSideBarVo);
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/updateSideBar")
    @ApiOperation(value="更新侧边栏菜单", notes="更新侧边栏菜单")
    public Result<String> updateSideBar(@Validated @RequestBody ChatChannelSideBarUpdateVo chatChannelSideBarVo) {
        logger.info("更新侧边栏菜单:{}",chatChannelSideBarVo);

        ChatChannelSideBar info = chatChannelService.updateCusSidebarMenuInfo(chatChannelSideBarVo);
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/deleteSideBar")
    @ApiOperation(value="删除侧边栏菜单", notes="删除侧边栏菜单")
    public Result<String> deleteSideBar(@Validated @RequestBody DeleteVo delete) {
        logger.info("删除侧边栏菜单:{}",delete);

        ChatChannelSideBar info = chatChannelService.deleteSidebarMenuInfo(delete.getId());
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/listSideBar")
    @ApiOperation(value="删除侧边栏菜单", notes="删除侧边栏菜单")
    public Result<Page<ChatChannelSideBar>> listSideBar(@Validated @RequestBody ChatChannelSideBarSearchVo chatChannelSideBarVo) {
        logger.info("删除侧边栏菜单:{}",chatChannelSideBarVo);

        Page<ChatChannelSideBar> page = chatChannelService.listSideBar(chatChannelSideBarVo);
        return ResultGenerator.genSuccessResult(page);
    }

    @PostMapping("/addExtModel")
    @ApiOperation(value="添加拓展菜单", notes="添加拓展菜单")
    public Result<String> add(@Validated @RequestBody ChatChannelExtModelInsertVo chatChannelExtModelVo) {
        logger.info("添加拓展菜单:{}",chatChannelExtModelVo);

        ChatChannelExtModel info = chatChannelService.addExtModel(chatChannelExtModelVo);
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/deleteExtModel")
    @ApiOperation(value="删除拓展菜单", notes="删除拓展菜单")
    public Result<String> deleteExtModel(@Validated @RequestBody DeleteVo delete) {
        logger.info("删除拓展菜单:{}",delete);

        ChatChannelExtModel info = chatChannelService.deleteExtModel(delete.getId());
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/updateExtModel")
    @ApiOperation(value="更新拓展菜单", notes="更新拓展菜单")
    public Result<String> updateExtModel(@Validated @RequestBody ChatChannelExtModelUpdateVo chatChannelExtModelVo) {
        logger.info("更新拓展菜单:{}",chatChannelExtModelVo);

        ChatChannelExtModel info = chatChannelService.updateExtModel(chatChannelExtModelVo);
        return ResultGenerator.genSuccessResult(info.getChannelId());
    }

    @PostMapping("/listExtModel")
    @ApiOperation(value="查询拓展菜单", notes="查询拓展菜单")
    public Result<Page<ChatChannelExtModel>> listExtModel(@Validated @RequestBody ChatChannelExtModelSearchVo chatChannelExtModelVo) {
        logger.info("查询拓展菜单:{}",chatChannelExtModelVo);

        Page<ChatChannelExtModel> page = chatChannelService.listExtModel(chatChannelExtModelVo);
        return ResultGenerator.genSuccessResult(page);
    }
}
